package ntrees.hu.listanima;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.Interpolator;
import android.view.animation.LayoutAnimationController;
import android.view.animation.TranslateAnimation;
import android.view.animation.LayoutAnimationController.AnimationParameters;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ListAnima extends Activity {
	private ListView list;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        list = (ListView) findViewById(R.id.list);
        list.setAdapter(new MyAdapter());
        
        AnimationSet set = new AnimationSet(true);

        Animation animation = new AlphaAnimation(0.0f, 1.0f);
        animation.setDuration(1000);
        set.addAnimation(animation);

        animation = new TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f
        );
        animation.setDuration(1000);
        set.addAnimation(animation);

        MyLayoutAnim controller = new MyLayoutAnim(set, 0.5f);
        list.setLayoutAnimation(controller);
    }
    
    //class MyListener extends LayoutAnimationLis
    
    class MyLayoutAnim extends LayoutAnimationController {
    	float delay = 0.5f;
    	long delayForView;
    	public MyLayoutAnim(Animation animation, float delay) {
			super(animation, delay);
		}

		public MyLayoutAnim(Animation animation) {
			super(animation);
		}
    	
		@Override
		public Animation getAnimation() {
			Log.d("", "------------ getAnimation");
			return super.getAnimation();
		}

		@Override
		public float getDelay() {
			Log.d("", "------------ getDelay");
			return delay += 0.5f;
			//return super.getDelay();
		}

		@Override
		protected long getDelayForView(View view) {
			//return delay += 0.5f;
			//delayForView = super.getDelayForView(view);
			delayForView += 100;
			Log.d("", "------------ getDelayForView" + (/*super.getDelayForView(view) + */delayForView));
			return /*super.getDelayForView(view) + */delayForView;
		}

		@Override
		public Interpolator getInterpolator() {
			Log.d("", "------------ getInterpolator");
			return super.getInterpolator();
		}

		@Override
		public int getOrder() {
			Log.d("", "------------ getOrder: " + super.getOrder());
			return super.getOrder();
		}

		@Override
		protected int getTransformedIndex(AnimationParameters params) {
			// TODO Auto-generated method stub
			Log.d("", "------------ getTransformedIndex");
			return super.getTransformedIndex(params);
		}

		@Override
		public boolean isDone() {
			Log.d("", "------------ isDone");
			// TODO Auto-generated method stub
			return super.isDone();
		}

		@Override
		public void start() {
			// TODO Auto-generated method stub
			Log.d("", "------------ start");
			super.start();
		}

		@Override
		public boolean willOverlap() {
			// TODO Auto-generated method stub
			Log.d("", "------------ willOverlap");
			return super.willOverlap();
		}
		
    }
    
    class MyAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 5;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			TextView tv = new TextView(ListAnima.this);
			tv.setBackgroundResource(R.drawable.pfocusbasebackgroud);
			tv.setText(mStrings[position]);
			tv.setTextColor(Color.WHITE);
			tv.setTextSize(26);
			return tv;
		}
    }
    
    private String[] mStrings = {
            "Bordeaux",
            "Lyon",
            "Marseille",
            "Nancy",
            "Paris",
            "Toulouse",
            "Strasbourg"
        };
}